package com.edward.action;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.edward.model.BalanceList;
import com.edward.service.BalanceListManager;
import com.opensymphony.xwork2.ActionSupport;

public class PrintBalanceListAction extends ActionSupport {

	private static final long serialVersionUID = 7000562419610510545L;

	private List<String> list;

	private Map<String, Object> map;

	private BalanceListManager balanceListManager;

	private BalanceList balanceList;

	public BalanceList getBalanceList() {
		return balanceList;
	}

	public void setBalanceList(BalanceList balanceList) {
		this.balanceList = balanceList;
	}

	public void setBalanceListManager(BalanceListManager balanceListManager) {
		this.balanceListManager = balanceListManager;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	public Map<String, Object> getMap() {
		return map;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}

	public String execute() throws Exception {
		BalanceList b = balanceListManager.getBalanceList(balanceList.getId());
		list = Arrays.asList(new String[] { "1" });//返回一个定长的List
		map = testReflect(b);
		return SUCCESS;
	}

	private static Map<String, Object> testReflect(Object obj) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		try {
			Class<? extends Object> c = obj.getClass();
			Method m[] = c.getDeclaredMethods();
			for (int i = 0; i < m.length; i++) {
				if (m[i].getName().indexOf("get") == 0) {
					hashMap
							.put(m[i].getName(), m[i]
									.invoke(obj, new Object[0]));
				}
			}
		} catch (Throwable e) {
			System.err.println(e);
		}
		return hashMap;
	}

}
